import { Body, Controller, Get, Post, Query, Res } from "@nestjs/common"
import { AliPayService } from "./aliPay.service"
import { Response } from "express"

@Controller("aliPay")
export class AliPayController {
  constructor(private readonly aliPayService: AliPayService) {}

  // Initiation of payment
  @Get("/pay")
  async pay(@Query() query: object, @Res() res: object): Promise<void> {
    await this.aliPayService.doPay(query, res)
  }
  // Payment callback
  @Post("/notify")
  async notify(@Body() body: any) {
    return this.aliPayService.notify(body)
  }

  // Obtain payment configuration
  @Get("/getConfig")
  async getConfig(@Res() res: any): Promise<void> {
    return this.aliPayService.getConfig(res)
  }

  // Save payment configuration
  @Post("/saveConfig")
  async saveConfig(@Body() body: any, @Res() res: any): Promise<void> {
    return await this.aliPayService.saveConfig(body, res)
  }

  // Whether the payment is open
  @Get("/isOpen")
  async isOpen(@Res() res: Response): Promise<void> {
    return await this.aliPayService.isOpen(res)
  }
}
